package com.jufa_3.common;

import lombok.Data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public class R<T> implements Serializable {  //返回结果R实现序列化接口Serializable才能将数据序列化以便缓存到redis数据库中

    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

//    private Map map = new HashMap(); //动态数据

    public static <T> R<T> success(T object) {
        R<T> r = new R<T>();
        r.code = 1000;
        r.msg = "成功";
        r.data = object;
        return r;
    }

    public static <T> R<T> success(T object, String msg) {
        R<T> r = new R<T>();
        r.code = 1000;
        r.data = object;
        r.msg = msg;
        return r;
    }

    public static <T> R<T> success(int code, T object) {
        R<T> r = new R<T>();
        r.code = code;
        r.data = object;
        return r;
    }

    public static <T> R<T> error(int code, String msg) {
        R r = new R();
        r.code = code;
        r.msg = msg;
        return r;
    }

//    public R<T> add(String key, Object value) {
//        this.map.put(key, value);
//        return this;
//    }
}
